<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // function fn1 (cb) {
        //     setTimeout(() => {
        //         console.log('fn1');
        //         cb&&cb();
        //     },1000)
        // }
        // function fn2 (cb) {
        //     setTimeout(() => {
        //         console.log('fn2');
        //         cb&&cb();
        //     },1000)
        // }
        // function fn3 (cb) {
        //     setTimeout(() => {
        //         console.log('fn3');
        //         cb&&cb();
        //     },1000)
        // }
        // fn1(function() {
        //     fn2(function() {
        //         fn3();
        //     });
        // });


        function fn1 (cb) {
            return new Promise(resolve => {
                setTimeout(() => {
                    console.log('fn1');
                    cb&&cb();
                    resolve('succeed');
                },1000)
            })
            
        }
        function fn2 (cb) {
            return new Promise(resolve => {
                setTimeout(() => {
                    console.log('fn2');
                    resolve('succeed');
                },1000)

            })
        }
        function fn3 (cb) {
            return new Promise(resolve => {
                setTimeout(() => {
                    console.log('fn3');
                    cb&&cb();
                    resolve('succeed');
                },1000)

            })
        }
        // fn1(function() {
        //     fn2(function() {
        //         fn3();
        //     });
        // });
        fn1().then(res => {
            return fn2();
        }).then(res => {
            return fn3();
        })

        // fn2();
        // fn3();

    </script>
</body>
</html>